<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>练习2</title>
		<script type="text/javascript">
			//定义一个构造函数
			function Student(stuid,chinese,math,english){
				this.stuid = stuid;
				this.chinese = chinese;
				this.math = math;
				this.english = english;
				this.sum = 0;
				this.studay = function(){
					console.log("学号为"+ this.stuid +"同学的总分是：" + (this.chinese + this.math + this.english));
					this.sum = this.chinese + this.math + this.english;
				}
			}
			
			//创建10个学生对象
			let stu1 = new Student(1,105,62,118);
			let stu2 = new Student(2,89,78,120);
			let stu3 = new Student(3,86,64,80);
			let stu4 = new Student(4,78,99,91);
			let stu5 = new Student(5,107.5,97,70);
			let stu6 = new Student(6,112,61,92);
			let stu7 = new Student(7,101,79,104);
			let stu8 = new Student(8,71,72,105);
			let stu9= new Student(9,56,68,61);
			let stu10 = new Student(10,98,83,77);
			
			let arr = [];
			arr.push(stu1);
			arr.push(stu2);
			arr.push(stu3);
			arr.push(stu4);
			arr.push(stu5);
			arr.push(stu6);
			arr.push(stu7);
			arr.push(stu8);
			arr.push(stu9);
			arr.push(stu10);
			
			let chinese_sum = 0;
			let max = 0;
			let max_sum_index = 0;
			for (var i = 0; i < arr.length; i++) {
				chinese_sum += arr[i].chinese;
				arr[i].studay();
				if(arr[i].sum > max) {
					max = arr[i].sum;
					max_sum_index = i;
				}
			}
			console.log("---------------------------------------");
			console.log("---------------------------------------");
			console.log(arr.length + "名同学的语文平均分是：" + chinese_sum/arr.length);
			console.log("---------------------------------------");
			console.log("---------------------------------------");
			console.log("班级第一名同学的学号是：" + arr[max_sum_index].stuid + "，语文成绩是：" + arr[max_sum_index].chinese + "，数学成绩是：" 
			+ arr[max_sum_index].math + "，英语成绩是：" + arr[max_sum_index].english);
		</script>
	</head>
	<body>
	</body>
</html>
